#!/usr/bin/python
# -*- coding: utf-8 -*-

import Ice, sys
import RobotFactoryI
from RobotFactoryI import *

try:
    HOME = os.environ['ROBOTS']
except KeyError:
    print 'ROBOTS environment variable is not currently defined.'
    sys.exit(0)

SLICE = os.path.join(HOME, 'slice')
FILE = os.path.join(SLICE, 'Robots.ice')
Ice.loadSlice('--all -I/usr/share/slice', ['-I' + SLICE, FILE])

import Robots

class Server (Ice.Application):

    def run (self, argv):
        self.shutdownOnInterrupt()

        adapter = self.communicator().createObjectAdapterWithEndpoints(
            'Adapter', 'default -p 9898')
        adapter.activate()

        adapter.add(RobotFactoryI(),
                    self.communicator().stringToIdentity('RobotFactory'))

        self.communicator().waitForShutdown()

        return 0

Server().main(sys.argv, os.path.join(HOME, 'config', 'config.server'))
